Skip to content

fix: prevent '?' shortcut from intercepting input in code editors#3065

Open
kartik-py12 wants to merge 1 commit intorust-lang:masterfrom
kartik-py12:fix-shortcut-intercept
Open

fix: prevent '?' shortcut from intercepting input in code editors#3065
kartik-py12 wants to merge 1 commit intorust-lang:masterfrom
kartik-py12:fix-shortcut-intercept

Conversation

@kartik-py12
Copy link
Copy Markdown

This adds a guard to the global keydown listener in book.js so that the '?' shortcut does not intercept keypresses when the user is focused inside an input, textarea, or Ace editor block.

Fixes #3064 and rust-lang/rust-by-example#1984

Copilot AI review requested due to automatic review settings April 10, 2026 19:16
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Apr 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an early guard to the global keydown handler so the ? help shortcut (and other navigation shortcuts handled there) won’t intercept keystrokes while the user is typing in editable UI (inputs/textareas/contenteditable/Ace editor), addressing the embedded editor “can’t type ?” regression.

Changes:

  • Guard chapterNavigation keydown handling when the event target is an editable element.
  • Treat Ace editor DOM (.ace_editor) as editable to avoid intercepting typing in playground editors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

View changes since this review

Comment on lines +657 to +662
const target = e.target;

// Do not intercept shortcuts when the user is typing in an input element or code editor
if (
target.tagName === 'INPUT' ||
target.tagName === 'TEXTAREA' ||
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added guard contains trailing whitespace (including the blank line after const target = e.target; and spaces after ||), which violates the repo’s ESLint no-trailing-spaces rule and will fail npm run lint. Please remove the trailing spaces so the file passes lint.

Copilot uses AI. Check for mistakes.
Comment on lines +663 to +665
target.isContentEditable ||
(target.closest && target.closest('.ace_editor'))
) {
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(target.closest && target.closest('.ace_editor')) has unnecessary parentheses; with no-extra-parens enabled in ESLint, this is likely to be reported as a lint error. Consider removing the wrapping parentheses while keeping the short-circuit guard.

Copilot uses AI. Check for mistakes.
@kartik-py12 kartik-py12 force-pushed the fix-shortcut-intercept branch 2 times, most recently from 4c682c8 to ffab758 Compare April 10, 2026 20:19
This adds a guard to the global keydown listener in book.js so that the '?' shortcut does not intercept keypresses when the user is focused inside an input, textarea, or Ace editor block.

Fixes rust-lang#3064
@kartik-py12 kartik-py12 force-pushed the fix-shortcut-intercept branch from ffab758 to 39301c4 Compare April 10, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shortcuts intercepting '?' in interactive exercises/playgrounds

3 participants